#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/wait.h>

void signcallback(int sig){
  printf("sig is %d\n",sig);
  sleep(10);
  //等待子进程退出，子进程已经退出了，wait不会进行阻塞
  wait(NULL);
}

int main(){
  pid_t pid=fork();
  if(pid<0){
    perror("fork");
    return 0;
  }else if(pid==0){
    //child
    sleep(20);
    exit(1);

  }else{
    //father
    signal(SIGCHLD,signcallback);
    while(1){
      printf("i am father\n");
      sleep(1);
    }
  }
  return 0;
}
